<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>canvas学习</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
    </style>
</head>

<body>
    <canvas id="tutorial" width="300" height="300">你的浏览器不支持 canvas，请升级你的浏览器。</canvas>
    <script>
        let canvas = document.getElementById('tutorial');
        //获得 2d 上下文对象
        if (canvas.getContext) {
            let ctx = canvas.getContext('2d');
            ctx.fillStyle = "rgb(200,0,0)";
            //绘制矩形
            ctx.fillRect(10, 10, 55, 50);

            ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
            ctx.fillRect(30, 30, 100, 100);
        } else {
            console.log("您的浏览器不支持canvas!");
        }
    </script>
</body>

</html>